//
//  CinemaViewController.m
//  豆瓣YHY
//
//  Created by dllo on 15/10/31.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "CinemaViewController.h"
#import "CinemaTableViewCell.h"
#import "AppTools.h"
#import "Cinema.h"
#import "MBProgressHUD.h"
@interface CinemaViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,retain)NSMutableArray *myarray;
@property (nonatomic,retain)MBProgressHUD *pug;
@end

@implementation CinemaViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor yellowColor];
    self.navigationItem.title = @"影院";
    UITableView *tableView = [[UITableView alloc]initWithFrame:[[UIScreen mainScreen]bounds] style:UITableViewStylePlain];
    tableView.backgroundColor  = [UIColor redColor];
    tableView.delegate = self;
    tableView.dataSource  = self;
    
    [tableView registerClass:[CinemaTableViewCell class] forCellReuseIdentifier:@"cell"];
    self.myarray = [[NSMutableArray alloc]init];
    //小菊花
    self.pug = [MBProgressHUD showHUDAddedTo:self.view animated:YES ];
    [self.pug show:YES];
    self.pug.labelText = @"正在";
    
    [AppTools getLocalDataWithURL:@"http://project.lanou3g.com/teacher/yihuiyun/lanouproject/cinemalist.php" andBlock:^(id dic) {
      //  NSLog(@"fff");
        NSMutableDictionary *dica =dic;
        //NSLog(@"%@",dica);
        NSDictionary *result = [dica objectForKey:@"result"];
      //  NSLog(@"wwww%@",result);
        NSMutableArray *arrayresult = [result objectForKey:@"data"];//data是数组
        //NSLog(@"%@",arrayresult);
        for (NSDictionary *dicdata in arrayresult) {
           // NSLog(@"zz");
            Cinema *cinema = [[Cinema alloc]init];//属性
              [cinema setValuesForKeysWithDictionary:dicdata];//属性赋值
           
            
            NSLog(@"%@",dicdata);
            [self.myarray addObject:cinema];//把每一行信息添加到数组里
            
        //    NSLog(@"%@",self.myarray);
        }
        [self.pug hide:YES]; // 小菊花消失

        [tableView reloadData];
    }];
   
    [self.view addSubview:tableView];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.myarray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *cell1 = @"cell";
   CinemaTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cell1];
    Cinema *cinema = [self.myarray objectAtIndex:indexPath.row];
    NSLog(@"zzzzzz%@",[self.myarray objectAtIndex:indexPath.row]);
    cell.cinema = cinema;
    //cell.textLabel.text = @"zz";
    return cell;
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 200;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
